﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CROSLAND.BL.BE;
using System.Data;
using DECOR.DL.DALC.SAPC.Proxy;

namespace CROSLAND.DL.DALC.SAPC
{
    public class TipoDocumentoDALC : ITipoDocumentoDALC
    {
       public static TipoDocumentoDALC Instance() {
            if (_instance == null)
            {
                lock (typeof(TipoDocumentoDALC))
                {
                    if (_instance == null)
                    {
                        _instance = new TipoDocumentoDALC();
                    }
                }
            }
            return _instance;
        }

        private TipoDocumentoDALC() { }
        private static volatile TipoDocumentoDALC _instance = null;


        #region ITipoDocumentoDALC Members

        public List<TipoDocumentoBE> listar()
        {
            TiposDocumentoProxy tProxy = new TiposDocumentoProxy();
            tProxy.Connection = DALC.getConnection;
            if (!tProxy.Connection.IsOpen) { tProxy.Connection.Open(); }
            /* llamando a la función */
            string ex_result = "";
            TVAKTTable tblTipoDocumento = new TVAKTTable();
            tProxy.Zweb_Lista_Documentoventas(out ex_result, ref tblTipoDocumento);
            SAP.Connector.SAPConnectionPool.ReturnConnection(tProxy.Connection);
            tProxy.Connection = null;
            /* Manejando el retorno */
            DataTable dt = tblTipoDocumento.ToADODataTable();

            List<TipoDocumentoBE> lsTipoDocumento = new List<TipoDocumentoBE>();
            foreach (DataRow dr in dt.Rows)
            {
                TipoDocumentoBE objTipoDocumento = new TipoDocumentoBE();
                objTipoDocumento.Codigo = dr["AUART"].ToString();
                objTipoDocumento.Descripcion = dr["AUART"].ToString() + " :: " + dr["BEZEI"].ToString();
                lsTipoDocumento.Add(objTipoDocumento);
            }
            return lsTipoDocumento;
        }

        #endregion
    }
}
